<template>
  <div class="channel-list-wrap">
    <el-form :inline="true" label-width="120px" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item :label="$t('channel.type')">
        <ren-select v-model="dataForm.type" dict-type="source_type" :placeholder="$t('channel.type')"></ren-select>
      </el-form-item>
      <el-form-item :label="$t('channel.name')">
        <el-input v-model="dataForm.title" :placeholder="$t('channel.name')" clearable></el-input>
      </el-form-item>
      <el-form-item :label="$t('channel.status')">
        <ren-select v-model="dataForm.status" dict-type="source_status" :placeholder="$t('channel.status')"></ren-select>
      </el-form-item>
      <el-form-item :label="$t('channel.create')">
        <el-input v-model="dataForm.createId" :placeholder="$t('channel.create')" clearable></el-input>
      </el-form-item>
      <el-form-item :label="$t('channel.date')">
        <el-date-picker v-model="dataForm.date" type="datetimerange" :placeholder="$t('channel.date')"> </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="reset()">{{ $t("reset") }}</el-button>
      </el-form-item>
    </el-form>
    <div class="channel-list-wrap__options-list">
      <el-button type="danger" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
    </div>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="code" :label="$t('channel.code')" sortable="custom" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('channel.type')" header-align="center" align="center">
        <template v-slot="scope">{{ scope.row.type == 2 ? "临时活动" : "固定渠道" }}</template>
      </el-table-column>
      <el-table-column prop="title" :label="$t('channel.name1')" header-align="center" align="center" width="150px"></el-table-column>
      <el-table-column prop="createTime" :label="$t('channel.date')" sortable="custom" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('channel.childCount')" sortable="custom" header-align="center" align="center" width="150px">
        <template v-slot="scope">
          二级来源：{{ scope.row.subCount }}个<br />
          三级来源：{{ scope.row.thirdCount }}个
        </template>
      </el-table-column>
      <el-table-column label="渠道星级" sortable="custom" header-align="center" align="center">
        <template v-slot="scope"> {{ scope.row.level }}星 </template>
      </el-table-column>
      <el-table-column prop="status" :label="$t('channel.status')" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="!scope.row.status" size="small" type="danger">下架</el-tag>
          <el-tag v-else size="small" type="success">上架</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView1";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./edit.vue";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/channel/list",
      getDataListIsPage: true,
      // deleteURL: "/demo/product",
      deleteIsBatch: true,
      dataForm: {
        type: "",
        title: "",
        status: "",
        createId: "",
        date: []
      },
      keys: {
        date: ["createTimeStart", "createTimeEnd"]
      }
    });
    return { ...useView(state), ...toRefs(state) ,
    
      reset(){
          state.dataForm = {
            type: "",
            title: "",
            status: "",
            createId: "",
            date: []
          },
          state.keys = {
            date: ["createTimeStart", "createTimeEnd"]
          }
      },
    };
  }
});
</script>
<style lang="sass" scoped>
.channel-list-wrap
  &__options-list
    margin-bottom: 22px
    display: flex
    flex-direction: row
    justify-content: flex-end
</style>
